from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-10 14:15:01.742926
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 10, Feb, 2021
Time: 14:15:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.0505
Nobs: 198.000 HQIC: -46.9402
Log likelihood: 2268.42 FPE: 2.24763e-21
AIC: -47.5452 Det(Omega_mle): 1.44259e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.468667 0.141462 3.313 0.001
L1.Burgenland 0.082438 0.072749 1.133 0.257
L1.Kärnten -0.217651 0.061383 -3.546 0.000
L1.Niederösterreich 0.130832 0.169208 0.773 0.439
L1.Oberösterreich 0.243760 0.148562 1.641 0.101
L1.Salzburg 0.201109 0.078586 2.559 0.010
L1.Steiermark 0.100913 0.105371 0.958 0.338
L1.Tirol 0.147700 0.070670 2.090 0.037
L1.Vorarlberg -0.003251 0.065012 -0.050 0.960
L1.Wien -0.140630 0.142269 -0.988 0.323
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.494194 0.171115 2.888 0.004
L1.Burgenland 0.017129 0.087999 0.195 0.846
L1.Kärnten 0.364997 0.074250 4.916 0.000
L1.Niederösterreich 0.122949 0.204677 0.601 0.548
L1.Oberösterreich -0.133172 0.179703 -0.741 0.459
L1.Salzburg 0.191764 0.095058 2.017 0.044
L1.Steiermark 0.215707 0.127459 1.692 0.091
L1.Tirol 0.139384 0.085484 1.631 0.103
L1.Vorarlberg 0.175737 0.078639 2.235 0.025
L1.Wien -0.576969 0.172091 -3.353 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307778 0.062782 4.902 0.000
L1.Burgenland 0.104257 0.032286 3.229 0.001
L1.Kärnten -0.019398 0.027242 -0.712 0.476
L1.Niederösterreich 0.072723 0.075095 0.968 0.333
L1.Oberösterreich 0.284225 0.065932 4.311 0.000
L1.Salzburg 0.003696 0.034877 0.106 0.916
L1.Steiermark -0.015547 0.046764 -0.332 0.740
L1.Tirol 0.088137 0.031364 2.810 0.005
L1.Vorarlberg 0.109290 0.028853 3.788 0.000
L1.Wien 0.070422 0.063140 1.115 0.265
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222749 0.070889 3.142 0.002
L1.Burgenland -0.012170 0.036456 -0.334 0.739
L1.Kärnten 0.023471 0.030760 0.763 0.445
L1.Niederösterreich 0.041810 0.084793 0.493 0.622
L1.Oberösterreich 0.382669 0.074447 5.140 0.000
L1.Salzburg 0.093278 0.039381 2.369 0.018
L1.Steiermark 0.182949 0.052803 3.465 0.001
L1.Tirol 0.040845 0.035414 1.153 0.249
L1.Vorarlberg 0.089616 0.032579 2.751 0.006
L1.Wien -0.067329 0.071293 -0.944 0.345
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.521210 0.142026 3.670 0.000
L1.Burgenland 0.057194 0.073039 0.783 0.434
L1.Kärnten 0.015707 0.061628 0.255 0.799
L1.Niederösterreich -0.040561 0.169883 -0.239 0.811
L1.Oberösterreich 0.149820 0.149154 1.004 0.315
L1.Salzburg 0.060992 0.078899 0.773 0.439
L1.Steiermark 0.130268 0.105791 1.231 0.218
L1.Tirol 0.212195 0.070952 2.991 0.003
L1.Vorarlberg 0.029044 0.065271 0.445 0.656
L1.Wien -0.126118 0.142836 -0.883 0.377
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160811 0.100047 1.607 0.108
L1.Burgenland -0.020788 0.051451 -0.404 0.686
L1.Kärnten -0.012178 0.043413 -0.281 0.779
L1.Niederösterreich 0.107715 0.119670 0.900 0.368
L1.Oberösterreich 0.389196 0.105068 3.704 0.000
L1.Salzburg -0.018341 0.055579 -0.330 0.741
L1.Steiermark -0.022799 0.074523 -0.306 0.760
L1.Tirol 0.191844 0.049981 3.838 0.000
L1.Vorarlberg 0.035026 0.045979 0.762 0.446
L1.Wien 0.196908 0.100618 1.957 0.050
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.233876 0.128849 1.815 0.070
L1.Burgenland 0.059012 0.066263 0.891 0.373
L1.Kärnten -0.038396 0.055910 -0.687 0.492
L1.Niederösterreich -0.043037 0.154121 -0.279 0.780
L1.Oberösterreich -0.091518 0.135316 -0.676 0.499
L1.Salzburg 0.038930 0.071579 0.544 0.587
L1.Steiermark 0.397282 0.095976 4.139 0.000
L1.Tirol 0.493486 0.064369 7.667 0.000
L1.Vorarlberg 0.164896 0.059215 2.785 0.005
L1.Wien -0.213425 0.129584 -1.647 0.100
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.075043 0.154477 0.486 0.627
L1.Burgenland 0.026235 0.079442 0.330 0.741
L1.Kärnten -0.090322 0.067030 -1.347 0.178
L1.Niederösterreich 0.247376 0.184775 1.339 0.181
L1.Oberösterreich -0.005263 0.162229 -0.032 0.974
L1.Salzburg 0.234613 0.085815 2.734 0.006
L1.Steiermark 0.135786 0.115065 1.180 0.238
L1.Tirol 0.069558 0.077172 0.901 0.367
L1.Vorarlberg 0.042009 0.070993 0.592 0.554
L1.Wien 0.271503 0.155357 1.748 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.591817 0.081753 7.239 0.000
L1.Burgenland -0.029450 0.042043 -0.700 0.484
L1.Kärnten -0.004179 0.035474 -0.118 0.906
L1.Niederösterreich -0.037883 0.097787 -0.387 0.698
L1.Oberösterreich 0.293315 0.085855 3.416 0.001
L1.Salzburg 0.019468 0.045415 0.429 0.668
L1.Steiermark 0.011830 0.060895 0.194 0.846
L1.Tirol 0.080804 0.040841 1.978 0.048
L1.Vorarlberg 0.137960 0.037571 3.672 0.000
L1.Wien -0.059278 0.082219 -0.721 0.471
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137976 0.037348 0.201905 0.256379 0.064791 0.100924 -0.056811 0.174458
Kärnten 0.137976 1.000000 0.014664 0.191534 0.165255 -0.112126 0.156034 0.017962 0.315409
Niederösterreich 0.037348 0.014664 1.000000 0.312833 0.086293 0.221280 0.137218 0.057069 0.364761
Oberösterreich 0.201905 0.191534 0.312833 1.000000 0.299610 0.294562 0.107865 0.079513 0.135037
Salzburg 0.256379 0.165255 0.086293 0.299610 1.000000 0.155877 0.067291 0.089439 -0.011848
Steiermark 0.064791 -0.112126 0.221280 0.294562 0.155877 1.000000 0.108342 0.092218 -0.088474
Tirol 0.100924 0.156034 0.137218 0.107865 0.067291 0.108342 1.000000 0.161766 0.161116
Vorarlberg -0.056811 0.017962 0.057069 0.079513 0.089439 0.092218 0.161766 1.000000 0.070802
Wien 0.174458 0.315409 0.364761 0.135037 -0.011848 -0.088474 0.161116 0.070802 1.000000